package com.daytask.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;

import com.daytask.db.bean.Tasktype;
import com.daytask.util.DbManager;

public class DayDbUtils {
	Connection conn = DbManager.getInstance().getConnection();
	QueryRunner queryRunner = new QueryRunner();

	public void test(){
		try{
			String sql =" insert into tb_tasktype(name,caption) values('手动阀啦','撒旦法啊');";
			 PreparedStatement ps = 	conn.prepareStatement(sql);
			ps.execute();
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	
	public int updateTaskType(Tasktype taskType) {
		int result = 0;
		try {
			result = queryRunner
					.update(conn,
							"update tb_tasktype set name=?,caption=? wehre id=?",
							taskType.getName(), taskType.getCaption(),
							taskType.getId());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}

	public   int insertTaskType(Tasktype taskType) {
	 int result =0;
		try {
			result  = queryRunner.update(conn,
					"insert into tb_tasktype(name,caption ) values (?,?)",
					  taskType.getName(),taskType.getCaption());

		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static void main(String[] args) {
	System.out.println("begin ");
	
	Tasktype  obj = new Tasktype();
	obj.setName("中文数字");
	obj.setCaption("中文描述s");
	DayDbUtils  db = new DayDbUtils();
//	db.insertTaskType(obj);
	db.test();
	
	
	System.out.print("结束"	);;

	
	}
	

}
